
#include <iostream>
#include "base/thread/thread_pool.hpp"
#include <boost/asio.hpp>
#include "spdlog/spdlog.h"
#include "server/rtmp/rtmp_server.hpp"
#include "server/http/http_live_server.hpp"
#include <spdlog/sinks/stdout_sinks.h>
using namespace mms;

int main22(int argc, char* argv[])
{
    thread_pool_inst::get_mutable_instance().start(std::thread::hardware_concurrency());
    #if 0
    while(1){
        for(int i = 0; i < std::thread::hardware_concurrency(); i++){
            sleep(1);
            thread_pool_inst::get_mutable_instance().get_worker(i)->post(
                [i](){
                    std::cout << std::this_thread::get_id() << ": thread worker: " << i << std::endl;

                }
            );
        }
    }
    #else
    while (1)
    {
        for (int i = 0; i < std::thread::hardware_concurrency(); i++)
        {
            sleep(1);
            auto w = thread_pool_inst::get_mutable_instance().get_worker(-1);
            boost::asio::co_spawn(w->get_io_context(),[i]()->boost::asio::awaitable<void> {
                std::cout << std::this_thread::get_id() << ": co thread worker: " << i << std::endl;
                spdlog::info("spdlog info");
                co_return;
            }, boost::asio::detached);
        }
    }

#endif
    return 0;
}

int main(int argc, char* argv[])
{
    

    // std::shared_ptr<spdlog::logger> m_logger = spdlog::stdout_logger_mt("consoleStdout");
    // 设置打印格式
    // m_logger->set_pattern("[%Y-%m-%d %H:%M:%S] [%l] (%s:%#) (%t) %v");

    // spdlog::set_pattern("*** [%Y-%m-%d %H:%M:%S] [%l] (%s:%#) [thread %t] %v ***");
    // spdlog::set_default_logger(m_logger);
 
    thread_pool_inst::get_mutable_instance().start(std::thread::hardware_concurrency());
    RtmpServer rtmp_server(thread_pool_inst::get_mutable_instance().get_worker(-1));
    if(!rtmp_server.start(1935)){
        spdlog::error("start rtmp server failed");
        return -1;
    }else{
        spdlog::info("RtmpServer start success: port: {}",1935);
    }

    HttpLiveServer http_live_server(thread_pool_inst::get_mutable_instance().get_worker(-1));
    if(!http_live_server.start(8080)){
        spdlog::error("start http live server failed");
    }else{
        spdlog::info("HttpLiveServer start success: port: {}", 8080);
    }

    while(1){
        sleep(1000);
    }
    return 0;
}
